#include <myheader_c_plus.h>
#include <mutex>
#include <thread>

using std::endl;
using std::cout;
using std::mutex;
using std::unique_lock;
using std::lock_guard;
using std::thread;
int shared_var = 0;
mutex mux;
void test1()
{
    for(int i = 0; i < 2000000; ++i)
    {
        mux.lock();
        shared_var ++;
        mux.unlock();
    }

}
void test2()
{
    for(int i = 0; i < 2000000; ++i)
    {
        mux.lock();
        shared_var ++;
        mux.unlock();

    }
}

void unique_lock_test()
{
    for(int i = 0; i < 2000000; ++i)
    {
        unique_lock<mutex> lg(mux);
        shared_var ++;
        lg.unlock();
    }

}
void unique_lock_test2()
{
    for(int i = 0; i < 2000000; ++i)
    {
        unique_lock<mutex> lg(mux);
        shared_var ++;
        lg.unlock();
    }

}
void lock_guard_test()
{
    for(int i = 0; i < 2000000; ++i)
    {
        lock_guard<mutex> lg(mux);
        shared_var ++;
    }


}
void lock_guard_test2()
{
    for(int i = 0; i < 2000000; ++i)
    {
        lock_guard<mutex> lg(mux);
        shared_var ++;
    }


}
int main(int argc, char *argv[])
{
    thread th(unique_lock_test);
    thread th2(unique_lock_test2);


    th.join();
    th2.join();
    cout << "shared_var = " << shared_var << endl;
    return 0;
}

